package com.recruit.g1.user.controller;

import com.recruit.g1.user.base.response.JsonResult;
import com.recruit.g1.user.base.response.StatusCode;
import com.recruit.g1.user.pojo.dto.VerificationParam;
import com.recruit.g1.user.pojo.vo.VerificationVO;
import com.recruit.g1.user.service.VerificationService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;
///api/verification/getCurrentUserVerification
@RestController
@RequestMapping("/api/verification")
@Api(tags = "实名认证模块")
@Slf4j
public class VerificationController {
//https://www.axureshop.com/a/1557136.html
    @Resource
    private VerificationService verificationService;


    @PostMapping("/postForm/{verificationStatus}")
    @ApiOperation("提交实名认证信息")
    public JsonResult submitVerification(@RequestBody VerificationParam param, @PathVariable String verificationStatus) {
        System.err.println(param);
        System.err.println(param.getPortraitUrl());
        System.err.println(verificationStatus+"::verificationStatus");
        if("UNVERIFIED".equals(verificationStatus)){
            log.warn("getCurrentUserVerification"+param.getPortraitUrl());
            System.err.println("submitVerification--url"+param.getPortraitUrl());
            return new JsonResult(StatusCode.SUCCESS,verificationService.submitVerification(param));
        }else if("REJECTED".equals(verificationStatus)){
            //776
            //110101199001011234
            //null::getStatus()
            ///uploads/1.png::getPortraitUrl
            ///uploads/1.png::getNationalEmblemUrl
            System.out.println(param.getName());
            System.out.println(param.getIdNumber());
            System.out.println(param.getStatus()+"::getStatus()");
            System.out.println(param.getPortraitUrl()+"::getPortraitUrl");
            System.err.println(param.getNationalEmblemUrl()+"::getNationalEmblemUrl");
            /// //////////后边需要将传入的id修改成获取当前登录用户的id
            return new JsonResult(StatusCode.SUCCESS,verificationService.updateVerification(1L,param));
        }else{
            log.warn("getCurrentUserVerification"+param.getPortraitUrl());
            System.err.println("submitVerification--url"+param.getPortraitUrl());
            return new JsonResult(StatusCode.SUCCESS,verificationService.submitVerification(param));
        }
//44
//110101199001011234
//http://localhost:8080//uploads/1.png
//http://localhost:8080//uploads/1.png
    }


    @GetMapping("/getCurrentVerification/{id}")
    @ApiOperation("根据ID查询实名认证信息")
    public VerificationVO getVerificationById(@PathVariable Long id) {
        VerificationVO verificationVO = verificationService.getVerificationById(1L);
        return verificationVO;//JsonResult
    }


    @GetMapping("/getCurrentUserVerification")
    @ApiOperation("根据ID查询实名认证信息")
    public VerificationVO getCurrentUserVerification() {
        //后边需要先获取当前登录的用户，然后根据登录的用户信息查询他的实名认证信息
        VerificationVO verificationVO = verificationService.getVerificationById(1L);
        System.out.println("getCurrentUserVerification::获取当前用户的认证信息"+verificationVO);
        return verificationVO;//JsonResult
    }

//    @GetMapping("/getCurrentUserVerification")
//    @ApiOperation("根据ID查询实名认证信息")
//    public VerificationVO getCurrentUserVerification(@PathVariable Long id) {
//        System.out.println("getCurrentUserVerification");
//        //后边需要先获取当前登录的用户，然后根据登录的用户信息查询他的实名认证信息
//        VerificationVO verificationVO = verificationService.getVerificationById(id);
//        System.out.println("getCurrentUserVerification"+verificationVO);
//        return verificationVO;//JsonResult
//    }


    @GetMapping("/list")
    @ApiOperation("获取所有实名认证信息")
    public List<VerificationVO> getAllVerifications() {
        return verificationService.getAllVerifications();
    }

    @PutMapping("/{id}/approve")
    @ApiOperation("批准实名认证")
    public boolean approveVerification(@PathVariable Long id) {
        return verificationService.approveVerification(id);
    }

    @PutMapping("/{id}/reject")
    @ApiOperation(" 拒绝实名认证")
    public boolean rejectVerification(@PathVariable Long id) {
        return verificationService.rejectVerification(id);
    }

    @PutMapping("/{id}")
    @ApiOperation("更新实名认证信息")
    public boolean updateVerification(@PathVariable Long id, @RequestBody VerificationParam param) {
        return verificationService.updateVerification(id, param);
    }
}